package com.pointi.emoTools;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class emoLogManager
{
	// ____________________________________________________________________________________________________
	// Log
	
	public static void mLog(String inString)
	{
		//System.out.println(inString) ;
	}
	
	public static void mPrint(String inString)
	{
		System.out.println(inString) ;
	}
	
	// ____________________________________________________________________________________________________
	// Print Log to Text File
	
	public void printTXT(String inCallkey, String inModule, String inFunc, String content)
	{
		/*//
		
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss") ;
		content = content + " (" + formatter.format(new Date()) + ")" ;
		content = inCallkey + "_" + inModule + "_" + inFunc + "_" + content ;
		System.out.println(content) ;

		/*/
		
        String filePath = "C:\\Module\\Emoray_Log\\" ;
        File dir = new File(filePath) ;
         if (!dir.exists()) { dir.mkdirs() ; }
		
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd") ;
		String fileName = filePath + "LOG_" + formatter.format(new Date()) + ".txt" ;
		File file = new File(fileName) ;
		
		formatter = new SimpleDateFormat("HH:mm:ss") ;
		content = content + " (" + formatter.format(new Date()) + ")" ;
		
		content = inCallkey + "_" + inModule + "_" + inFunc + "_" + content ;

		if (fileName.length() == 0)
		{
			try
			{
				FileWriter file_writer = new FileWriter(file);
				BufferedWriter buff_writer = new BufferedWriter(file_writer);
				PrintWriter print_writer = new PrintWriter(buff_writer,true);
				print_writer.println(content);
				if(print_writer.checkError()) { System.out.println("print_writer error!!"); }
				file.createNewFile();
				print_writer.close();
			}
			catch (Exception e)
			{
				System.out.println("IO Exceiption!");
				e.printStackTrace();
			}
		}
		else
		{
			try
			{
				BufferedWriter buff_writer = new BufferedWriter(new FileWriter(file, true));
				PrintWriter print_writer = new PrintWriter(buff_writer,true);
				print_writer.println(content);

				if(print_writer.checkError()) { System.out.println("Print Writer Error !"); }
				
				print_writer.close();
			}
			catch (Exception e)
			{
				System.out.println("IO Exceiption!");
				e.printStackTrace();
			}
		}
		//*/
	}
}
